package org.senzacontrollo.designPatterns.composite;

import java.util.Vector;

public class Composite extends Component{

	private Vector<Component> components;
	
	public Composite(String name) {
		super(name);
		components = new Vector<Component>();
	}
	
	@Override
	public void add(Component comp) throws SinglePartException {
		components.add(comp);
	}

	@Override
	public void remove(Component comp) throws SinglePartException {
		components.remove(comp);
	}
	
	@Override
	public Component getChild(int n) throws SinglePartException {
		return components.get(n);
	}
	
	@Override
	public void describe() {
		System.out.println("I'm the composite" + name);
		System.out.print("I'm composed from {");
		
		for (Component comp : components){
				comp.describe();
		}
		System.out.println("}");

		
	}

}
